package com.ctshk.rpc.order.ship.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.order.ship.dto.ShipOrderPageDTO;
import com.ctshk.rpc.order.ship.entity.ShipOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.order.ship.req.ShipOrderPageReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 船票订单 Mapper 接口
 * </p>
 *
 * @author 刘蕾
 * @since 2021-03-16
 */
public interface ShipOrderMapper extends BaseMapper<ShipOrder> {

    /**
     * 获取订单详情
     * @param req
     * @param agentPage
     * @return
     */
    @Select("<script>"+" select t.id, t.order_number orderNumber, " +
            "t.trip_type tripType, " +
            "t.product_type productType, " +
            "case t2.company_type when '1' then '信德船舶' when '2' then '珠江船舶' end companyType, " +
            "t2.route_id routeId, " +
            "t2.route_name, " +
            "t2.ship_type_name shipTypeName, " +
            "t.dep_city_name depCityName, " +
            "t.arr_city_name arrCityName, " +
            "t.dep_place_name depPlaceName, " +
            "t.arr_place_name arrPlaceName, " +
            "t2.cabin_class_name cabinClassName, " +
            "t.order_amount orderAmount, " +
            "t.payment_status paymentStatus, " +
            "t.scheduled_status scheduledStatus, " +
            "t.contact_name contactName, " +
            "t.source, " +
            "t.voyage, " +
            "t.salesman_name createId, " +
            "t.salesman_name salesmanName, " +
            "t.gmt_create gmtCreate   " +
            " FROM " +
            " t_ship_order t " +
            " LEFT JOIN t_ship_order_tourist t1 ON t.id = t1.order_id " +
            " LEFT JOIN t_ship_order_route t2 ON t.id = t2.order_id  " +
            " where 1=1   " +
            "<if test=\"req.orderNumber != null and req.orderNumber != ''\"> AND T.order_number = #{req.orderNumber}</if>  " +
            "<if test=\"req.companyType != null and req.companyType != ''\"> AND T.company_type = #{req.companyType}</if>  " +
            "<if test=\"req.paymentStatus != null and req.paymentStatus != ''\"> AND T.payment_status = #{req.paymentStatus}</if>  " +
            "<if test=\"req.scheduledStatus != null and req.scheduledStatus != ''\"> AND T.scheduled_status = #{req.scheduledStatus}</if>  " +
            "<if test=\"req.voyage != null and req.voyage != ''\"> AND T2.voyage = #{req.voyage}</if>  " +
            "<if test=\"req.depCityId != null and req.depCityId != ''\"> AND T2.dep_city_id = #{req.depCityId}</if>  " +
            "<if test=\"req.arrCityId != null and req.arrCityId != ''\"> AND T2.arr_city_id = #{req.arrCityId}</if>  " +
            "<if test=\"req.depPlaceId != null and req.depPlaceId != ''\"> AND t2.dep_place_id = #{req.depPlaceId}</if>  " +
            "<if test=\"req.arrPlaceId != null and req.arrPlaceId != ''\"> AND t2.arr_place_id = #{req.arrPlaceId}</if>  " +
            "<if test=\"req.source != null and req.source != ''\"> AND t.source = #{req.source}</if>  " +
            "<if test=\"req.contactName != null and req.contactName != ''\"> AND t.contact_name LIKE CONCAT('%',#{req.contactName },'%')</if>  " +
            "<if test=\"req.saleManName != null and req.saleManName != ''\"> AND t.salesman_name LIKE CONCAT('%',#{req.saleManName },'%')</if>  " +
            "<if test=\"req.createDateStart != null and req.createDateEnd != null \"> AND T.gmt_create between #{req.createDateStart} and #{req.createDateEnd} </if>  " +
            "GROUP BY " +
            " t.id  order by t.gmt_create desc"+"</script>")
    IPage<ShipOrderPageDTO> queryList(@Param("req") ShipOrderPageReq req, IPage<ShipOrderPageDTO> agentPage);
}
